home *** CD-ROM | disk | FTP | other *** search
- :
- #
- # E-Mail address directory lookup script to read the sendmail aliases file,
- # password file, and user's .addresses file. (Format of .addresses file
- # is one address per line -- no comments or extra information.)
- #
- PATH=$PATH:/usr/local/bin
-
- if [ $# -ne 2 ]
- then
- echo "`basename $0`: Expected 2 args, got $#"
- exit 3 # Incorrect arguments
- fi
- matches=${TMPDIR-/tmp}/almatch$$
- domainname=`(domainname) 2>/dev/null`
- if test -n "$domainname"
- then
- domainname="-d $domainname"
- else
- hostname=`( hostname || uname -n || uuname -l ) 2>/dev/null`
- case "$hostname" in
- *.*) domainname="-d $hostname";;
- esac
- fi
- touch $matches
- # Read user's .addresses file
- if [ -z "$ADDRESSES" ]
- then
- ADDRESSES=$HOME/.addresses
- fi
- # Nice to do this, but it doesn't work.
- #egrep "$2" $ADDRESSES | awk '{ print $1 }' >> $matches 2>/dev/null
- (egrep -i "$2" $ADDRESSES || fgrep -i "$2" $ADDRESSES) >> $matches 2>/dev/null
- # see how many matches we made
- #
- # make SP = space + tab
- SP=`echo x | tr x '\011'``echo x | tr x '\040'`
- #
- #getaliases="(ypcat $hostname aliases || cat /usr/lib/aliases || cat /etc/aliases) 2>/dev/null"
- #eval "$getaliases" | sed 's/#.*//' | egrep -i \^"[^:]*$2[^:]*": | \
- # sed "s/\(.*\):[$SP]*\(.*\)"'/\2, forwarding address for <\1>/' >> $matches
- #sed "s/[$SP]*:[$SP]*"'\(.*\)/ (\1)/' >> $matches
- #
- # determine how to read the password file, then read it.
- #getpasswd="(ypcat $hostname passwd || cat /etc/passwd) 2>/dev/null"
- #eval "$getpasswd" | cut -d: -f1,5 | egrep -i "$2" | \
- # sed 's/^\([^:]*\):\(\([^,]*\).*\)$/\1 (\3), \2/' >> $matches
- #
-
- ADDR=`echo "'"$2"'"`
- getlocate="locate -t $ADDR"
- #eval "$getlocate" | sed "s/[$SP]/ /g" >> $matches
- #eval "$getlocate" | nawk -F\t '{printf ("%s %s %s %s|%s\n", $2, $3, $4, $5, $1)}' >> $matches
- eval "$getlocate" |\
- nawk '{A=substr($0,33,length($0)-32);
- D=substr($0,1,32);
- printf ("%s|%s\n", A, D)}' >> $matches
- sort -u -o $matches $matches 2>/dev/null
- count=`wc -l < $matches`
- #
- EXIT=1 # Execution failure
- if [ $count -eq 0 ]
- then
- echo "$2"
- EXIT=4 # No matches found
- elif [ $count -gt $1 ] && [ $1 -gt 0 ]
- then
- echo "Matched $count names (max $1)"
- echo "Use a more specific pattern please."
- EXIT=2 # Too many matches
- else
- cat $matches
- if [ $count -eq 1 ]
- then
- EXIT=5 # Exactly one match
- else
- EXIT=0 # At least one match
- fi
- fi
- rm -f $matches
- exit $EXIT
-